<include file="Public/mobile_head"/>
<script type="text/javascript" src="{:ADDON_PUBLIC_PATH}/mobile/shop.js?v={:SITE_VERSION}"></script>
<link href="{:ADDON_PUBLIC_PATH}/mobile/common.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
<link href="{:CUSTOM_TEMPLATE_PATH}Public/shop.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
<body>
    <div class="container">
    	<form class="search_form">
        	<a href="{:U('lists',array('shop_id'=>$shop_id))}" class="back_icon">&nbsp;</a>
            <input type="text" placeholder="输入关键字搜索商品" value="{:I('search_key')}" name="search_key" />
            <button type="button" id="search" url="{:U('lists',array('shop_id'=>$shop_id))}">搜索</button>
            <a href="javascript:void(0);" class="cate_icon" onClick="showPopCategory()">&nbsp;</a>
        </form>
         <empty name='goods'>
        	<br/><br/>
        	<p style="text-align: center;color: red;">抱歉，该商品不存在，已被删除</p>
        	<else />
        	<eq name='goods.is_show' value='0'>
        		<br/><br/>
        		<p style="text-align: center;color: red;">抱歉，该商品已下架</p>
        	<else />
        <!-- 相册 -->
        <section class="photoList">
        	<ul>
            <volist name="goods.imgs_url" id="url">
                <li>
                    <img src="{$url}"/>
                </li>
             </volist>            
            </ul>
            <span class="identify">
            <volist name="goods.imgs_url" id="vo">
                <em></em>
             </volist>  
            </span>
        </section>
        <!-- 详情信息 -->
        <form id="detailForm" action="{:addons_url('Shop://Wap/confirm_order')}" method="post">
        <input type="hidden" name="goods_id" value="{$goods.id}"/>
        <div class="detail_info">
        	<div class="info_item">
        		<h6 class="name">{$goods.title}</h6>
            	<p class="price">
                	￥<span id="price">{$goods.price|wp_money_format}</span>
                	<notempty name="goods.old_price"><del>￥{$goods.old_price|wp_money_format}</del></notempty>
                </p>
            </div>
            <div class="info_item">
<!--            	<p>型号</p>
            	<a class="sku_item" href="javascript:;" data-price="122.00">黄色 38<input type="checkbox" class="sku_check" name="sku[0]" value="1"/></a>
                <a class="sku_item select"href="javascript:;" data-price="122.00">绿色 39<input type="checkbox" class="sku_check" name="sku[1]" value="1"/></a>
                <a class="sku_item" href="javascript:;" data-price="122.00">红色 40<input type="checkbox" class="sku_check" name="sku[2]" value="1"/></a>-->
                <p>数量</p>
                <div class="buy_count">
                	<a class="reduce" href="javascript:;">-</a>
                    <input type="text" name="buyCount" value="1"/>
                    <a class="add" href="javascript:;">+</a>
                </div>
            </div>
        </div>
        <!--<div class="detail_comment">
        	<span class="t">评价：</span>
            <span class="star_rader">
            	<span class="star_select" style="width:20%"></span>
            </span>
            <span class="t comment_count">&nbsp;&nbsp;&nbsp;(23人)</span>
        </div>-->
        <!-- 商品介绍 -->
        <div class="detail_content">
        	<h6 class="t">商品介绍</h6>
            <div class="content">{$goods.content}
            </div>
        </div>
        </form>
    </div>
        <!-- 分类目录 -->
    <include file="_category"/>
    
    <!-- 底部加入购物车等 -->
    <div class="detail_bottom">
    	<a class="add_favorite" href="javascript:;" onClick="addToFavorite()">收藏</a>
        <a class="add_cart" href="javascript:;" onClick="addToCart()">加入购物车</a>
        <a class="buy_now" href="javascript:;" onClick="buyNow()">立即购买</a>
        <a class="my_cart" href="{:U('cart', array('shop_id'=>$shop_id))}">购物车<span class="count" id="cartCount">{$cart_count}</span></a>
    </div>
     </eq>
  </empty>
	<p class="copyright">{$system_copy_right}{$tongji_code}</p>
<script type="text/javascript">
//加入收藏
function addToFavorite(){
	var data = $('#detailForm').serializeArray();
	$.ajax({
		url:"{:U('addToCollect',array('shop_id'=>$shop_id))}",
		data:data,
		dataType:'JSON',
		type:"POST",
		success:function(data){
			if(data){
				$.Dialog.success("收藏成功");
			}
		}
	})
}
function addToCart(){
	if(parseInt($('input[name="buyCount"]').text())>0){
		$.Dialog.fail("购物数量不能小于1件");
		return;	
	}
//	if(!$('.sku_check:checked').val()){
//		$.Dialog.fail("请选择型号");
//		return;	
//	}
	var data = $('#detailForm').serializeArray();
	$.ajax({
		url:"{:U('addToCart',array('shop_id'=>$shop_id))}",
		data:data,
		dataType:'JSON',
		type:"POST",
		success:function(res){
			if(res){
				$.Dialog.success("加入购物车成功");
				$('#cartCount').text(res);
			}
		}
	})
}
function buyNow(){
	if(parseInt($('input[name="buyCount"]').text())>0){
		$.Dialog.fail("购物数量不能小于1件");
		return;	
	}
//	if(!$('.sku_check:checked').val()){
//		$.Dialog.fail("请选择型号");
//		return;	
//	}
	$('#detailForm').submit();
}
$(function(){
	$.WeiPHP.gallery('.photoList','.photoList ul');
	$('.sku_item').click(function(){
		$('#price').text($(this).data('price'));
		$(this).addClass('select').siblings().removeClass('select');
		$(this).find('input').prop("checked",true);
		$(this).siblings().find('input').prop("checked",false);
	})
	//图片预览
	var picList = [];
	$('.photoList li img').each(function(index, element) {
		var picUrl = $(this).attr("src");
		picList[index] = picUrl;
        $(this).click(function(){
			wx.previewImage({
				current: picUrl, // 当前显示的图片链接
				urls: picList // 需要预览的图片链接列表
			});
		})
    });
	
		//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search_form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});	
})
</script>	
</body>
</html>